/**
 * 根服务
 */
const Service = require('egg').Service
const { Pool } = require('pg')

class BaseService extends Service {
  /**
   * this中包含的属性
   * @param{ ctx, app, service, config, logger } = this
   */
  //postgre服务
  postgreServer () {
    const { config: { postgre } } = this
    const connectionString = `postgresql://${postgre.user}:${postgre.password}@${postgre.host + postgre.database}`
    return new Pool({
      max: 10,
      idleTimeoutMillis: 10000,
      connectionTimeoutMillis: 5000,
      connectionString
    })
  }
}

module.exports = BaseService 